Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Number of days in a Month*



    Hello, I have data on "mdate" (year and month). How can I generate a variable that indicates the number of days in the given year and month?


    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float mdate
    669
    710
    731
    676
    696
    683
    555
    564
    547
    544
    622
    528
    608
    540
    648
    647
    593
    615
    656
    602
    715
    603
    723
    612
    527
    711
    576
    668
    632
    655
    573
    690
    687
    625
    554
    645
    532
    698
    672
    535
    539
    636
    699
    531
    726
    618
    635
    577
    692
    663
    651
    665
    654
    587
    660
    611
    705
    572
    702
    570
    589
    553
    627
    582
    566
    713
    517
    516
    594
    631
    729
    633
    642
    541
    658
    659
    533
    688
    619
    616
    575
    561
    727
    681
    521
    624
    617
    662
    558
    596
    712
    643
    725
    637
    728
    722
    640
    614
    671
    599
    end
    format %tm mdate
    ------------------ copy up to and including the previous line ------------------

    Listed 100 out of 121176 observations
    Use the count() option to list more

  • #2
    Well, the current version of Stata, 18, has a built-in daysinmonth() function. So -gen wanted = daysinmonth(mdate)- will give you that. If you are using an older version, which you are supposed to say in your post, then this function is not available to you. In that case, you have to calculate it as:
    Code:
    gen wanted = dofm(mdate+1)-dofm(mdate)

    Comment


    • #3
      Thanks Clyde Schechter

      Comment

      Working...
      X